export default function (key, value) {
    var localStorage = window.localStorage
    if (arguments.length == 1) { //get
        var originValue = localStorage.getItem(key);
        if (/^\[\[\[(JSON|BOOL|NUMB)\]\]\]:/.test(originValue)) {
            var source = originValue.match(/^\[\[\[(JSON|BOOL|NUMB)\]\]\]:(.+)/);
            var dataType = source[1];
            var dataValue = source[2];
            value = ({
                JSON: function () {
                    return JSON.parse(dataValue);
                },
                BOOL: function () {
                    return dataValue == 'true' ? true : false;
                },
                NUMB: function () {
                    return parseFloat(dataValue);
                }
            })[dataType]();
        } else {
            value = originValue;
        }
        return value;
    } else { //set
        if (value == null) {
            localStorage.removeItem(key);
        } else {
            if (typeof value == 'number') {
                value = '[[[NUMB]]]:' + value;
            } else if (typeof value == 'object') {
                value = '[[[JSON]]]:' + JSON.stringify(value);
            } else if (typeof value == 'boolean') {
                value = '[[[BOOL]]]:' + value;
            }
            localStorage.setItem(key, value);
        }
    }
}